proc DC_100011 { req } {
	global dbConnection
        set handle $dbConnection
	puts "in DC_100011:req=$req"
	list_to_array $req r_array
	set cust_name [string trim $r_array(Cust_Name) ]
	set cust_addr [string trim $r_array(Cust_Address) ]
	set cust_kind [string trim $r_array(Cust_Kind) ]
	set cert_type [string trim $r_array(Cert_Type) ]
	set cert_num  [string trim $r_array(Cert_Num)  ]
	set login_account [string trim $r_array(Login_Account) ]
	set login_passwd  [string trim $r_array(Login_Passwd)  ]
	set contact       [string trim  $r_array(Contact) ]
	set contact_mobile [string trim $r_array(Contact_Mobile) ]
	set pstn          [string trim $r_array(Pstn) ]
	set account_addr  [string trim $r_array(Account_Address) ]
	set account_name  [string trim $r_array(Account_Name)  ]
	set user_type     [string trim $r_array(User_Type)  ]
	set svc_num       [string trim $r_array(Svc_Num)  ]
	set email 	  [string trim $r_array(Email) ]

	set sql "select cust_id from lbs_customer where cert_num='$cert_num' and cert_type='$cert_type'";
	puts $sql
	set cust_id 0
	set result [::mysql::sel $handle $sql -list ]
	puts "cust_id [lindex $result 0]"
	if {[lindex $result 0] == ""   } {
		set sql "select max(cust_id)+1 from lbs_customer "
		set result [::mysql::sel $handle $sql -list ]
		if {[lindex $result 0] == "{}" } {
			set cust_id 1
		} else {
			set cust_id [lindex $result 0]
		}
		set sql "select max(account_id)+1 from lbs_account "
		set result [::mysql::sel $handle $sql -list ]
		if {[lindex $result 0] == "{}" } {
			set account_id 1
		}  else {
			set account_id [lindex $result 0]
		}
		set sql "select max(user_id)+1 from lbs_subscription"
		set result [::mysql::sel $handle $sql -list ]
		puts "subs_id= $result"
		if { [lindex $result 0 ] == "{}" } {
			set user_id 1
		} else {
			set user_id [lindex $result 0]
		}
		
		set sql "insert into lbs_customer(cust_id,cust_name,address,cust_kind,cert_type,cert_num,login_account,login_password,contact,contact_mobile,pstn) values($cust_id,'$cust_name','$cust_addr','$cust_kind','$cert_type','$cert_num','$login_account','$login_passwd','$contact','$contact_mobile','$pstn')"
		puts $sql
		set result [::mysql::exec $handle $sql]
		set sql "insert into lbs_account(account_id,cust_id,account_name,account_address,email) values($account_id,$cust_id,'$account_name','$account_addr','$email')";
		puts $sql
		set result [::mysql::exec $handle $sql]
		set sql "insert into lbs_subscription(user_id,cust_id,account_id,user_type,svc_num,join_date,user_passwd) values($user_id,$cust_id,$account_id,'$user_type','$svc_num',now(),$login_passwd)"
		puts $sql
		set result [::mysql::exec $handle $sql]
		return "{{00000} {{$user_id} {$account_id} {$cust_id}} }"

	} else {
		set cust_id [lindex $result 0]
		set account_id 0
		set sql "select account_id from lbs_account where cust_id=$cust_id"
		puts $sql
		set result [::mysql::sel $handle $sql -list ]
		puts "lndex--------- [lindex $result 0]"
		if { [lindex $result 0 ] != "" } {
		set account_id [lindex $result 0]
		puts "acccount_id=$account_id"
		} else {
			set sql "select max(ifnull(account_id,0))+1 from lbs_account "
			set result [::mysql::sel $handle $sql -list ]
			puts "lndex [lindex $result 0]"
			if {[lindex $result 0] == "{}" } {
				set account_id 1
			set sql "insert into lbs_account(account_id,cust_id,account_name,account_address,email) values($account_id,$cust_id,'$account_name','$account_addr','$email')";
			puts $sql
			set result [::mysql::exec $handle $sql]
			} else {
				set account_id [lindex $result 0]
			}
			puts "acccount_id2=$account_id"
		}
		
		set sql "select max(user_id)+1 from lbs_subscription"
		set result [::mysql::sel $handle $sql -list ]
		puts "subs = [lindex $result 0 ] "
		if { [lindex $result 0 ] == "" || [lindex $result 0] == "{}" } {
			set user_id 1
		} else {
			set user_id [lindex $result 0]
		}
		set sql "insert into lbs_subscription(user_id,cust_id,account_id,user_type,svc_num,join_date,user_passwd) values($user_id,$cust_id,$account_id,'$user_type','$svc_num',now(),'$login_passwd')"
		puts $sql
		set result [::mysql::exec $handle $sql]
		return "{{00000} {{$user_id} {$account_id} {$cust_id}} }"
		
	}
	
}
